# vim: filetype=yaml sw=2
filename: 'container-image_[% c("var/container/suite") %]-[% c("var/container/arch") %]-[% c("version") %].tar.gz'
version: 3
pkg_type: build

var:
  ubuntu_version: 20.04.1

  container:
    use_container: 1
    # We need CAP_SYS_ADMIN for debootstrap to work
    CAP_SYS_ADMIN: 1

pre: |
  #!/bin/sh
  set -e
  export DEBIAN_FRONTEND=noninteractive
  apt-get update -y -q
  apt-get install -y -q debian-archive-keyring ubuntu-keyring debootstrap
  debootstrap --arch=[% c("var/container/arch") %] [% c("var/container/debootstrap_opt") %] [% c("var/container/suite") %] base-image [% c("var/container/debootstrap_mirror") %]
  [% IF c("var/apt_package_filename") || c("var/apt_utils_package_filename") || c("var/libapt_inst_package_filename") || c("var/libapt_pkg_package_filename") -%]
    mkdir ./base-image/apt-update
    mv [% c("var/apt_package_filename") %] [% c("var/apt_utils_package_filename") %] \
       [% c("var/libapt_inst_package_filename") %] [% c("var/libapt_pkg_package_filename") %] \
       ./base-image/apt-update
    mount proc ./base-image/proc -t proc
    mount sysfs ./base-image/sys -t sysfs
    chroot ./base-image dpkg -i -R /apt-update
    umount ./base-image/proc
    umount ./base-image/sys
  [% END -%]
  [% IF c("var/minimal_apt_version") -%]
    apt_version=$(dpkg --admindir=$(pwd)/base-image/var/lib/dpkg -s apt | grep '^Version: ' | cut -d ' ' -f 2)
    echo "apt version: $apt_version"
    dpkg --compare-versions "$apt_version" ge '[% c("var/minimal_apt_version") %]'
  [% END -%]
  tar -C ./base-image -czf [% dest_dir %]/[% c("filename") %] .

targets:
  wheezy-amd64:
    var:
      minimal_apt_version: '0.9.7.9+deb7u9'
      # https://deb.freexian.com/extended-lts/updates/ela-76-1-apt/
      apt_packages_baseurl: http://deb.freexian.com/extended-lts/pool/main/a/apt
      apt_package_filename: apt_0.9.7.9+deb7u9_amd64.deb
      apt_package_sha256sum: b8a218da2ae21979323dd02551d983938d94308ac56930a2d238e822f062dc61
      apt_utils_package_filename: apt-utils_0.9.7.9+deb7u9_amd64.deb
      apt_utils_package_sha256sum: d635a166aae03b24cdabe277bb46d584156836637c0b9bef2220fb0bc0928e40
      libapt_inst_package_filename: libapt-inst1.5_0.9.7.9+deb7u9_amd64.deb
      libapt_inst_package_sha256sum: 332083172e00d39e55dec4c7078c3522989e45e12b0a1306889e90b8e2c0a0db
      libapt_pkg_package_filename: libapt-pkg4.12_0.9.7.9+deb7u9_amd64.deb
      libapt_pkg_package_sha256sum: c3ae83c4ea691074250bf6fb175e71042c4bb7418bf19779ceda0a53eea0a257

      container:
        suite: wheezy
        arch: amd64
        debootstrap_mirror: "http://archive.debian.org/debian/"

  jessie-armhf:
    var:
      minimal_apt_version: 1.0.9.8.6
      apt_packages_baseurl: http://security.debian.org/debian-security/pool/updates/main/a/apt
      apt_package_filename: apt_1.0.9.8.6_armhf.deb
      apt_package_sha256sum: cdae944dd0e51b690befee867fd00fd7b5c20fe1227d1c76600b5300b1d2b955
      apt_utils_package_filename: apt-utils_1.0.9.8.6_armhf.deb
      apt_utils_package_sha256sum: 18bf2c6d871eaafb586744ccffede9f15499ba1313fb652cfebfdfc045ad3700
      libapt_inst_package_filename: libapt-inst1.5_1.0.9.8.6_armhf.deb
      libapt_inst_package_sha256sum: 5f85da2a59e9f6634b166e4a0a376f9c7777adf5b6767d91274c4242a28743c1
      libapt_pkg_package_filename: libapt-pkg4.12_1.0.9.8.6_armhf.deb
      libapt_pkg_package_sha256sum: 28a56875af6f1312f4af53faba6dab1a1c90437fab2829707561bb68e9bc385f

      container:
        suite: jessie
        arch: armhf

  stretch-armhf:
    var:
      minimal_apt_version: 1.4.9
      container:
        suite: stretch
        arch: armhf

  stretch-arm64:
    var:
      minimal_apt_version: 1.4.9
      container:
        suite: stretch
        arch: arm64

  buster-amd64:
    var:
      minimal_apt_version: 1.8.2
      container:
        suite: buster
        arch: amd64

  buster-arm64:
    var:
      minimal_apt_version: 1.8.2
      container:
        suite: buster
        arch: arm64

input_files:
  - URL: 'https://cdimage.ubuntu.com/ubuntu-base/releases/[% c("var/ubuntu_version") %]/release/ubuntu-base-[% c("var/ubuntu_version") %]-base-amd64.tar.gz'
    filename: 'container-image_ubuntu-base-[% c("var/ubuntu_version") %]-base-amd64.tar.gz'
    sha256sum: 97f6cbcf41f39272c84e32b6f926ed5d6906c6e463a557025181f4aa191ad667
    enable: '[% c("buildconf/deb_native_arch") == "amd64" %]'
  - URL: 'https://cdimage.ubuntu.com/ubuntu-base/releases/[% c("var/ubuntu_version") %]/release/ubuntu-base-[% c("var/ubuntu_version") %]-base-arm64.tar.gz'
    filename: 'container-image_ubuntu-base-[% c("var/ubuntu_version") %]-base-arm64.tar.gz'
    sha256sum: 269709ecd5c506f229f10983f990c394278b202ca29f089844e2e5c2b80ad8b4
    enable: '[% c("buildconf/deb_native_arch") == "arm64" %]'
  - URL: '[% c("var/apt_packages_baseurl") %]/[% c("var/apt_package_filename") %]'
    sha256sum: '[% c("var/apt_package_sha256sum") %]'
    enable: '[% c("var/apt_package_filename") %]'
  - URL: '[% c("var/apt_packages_baseurl") %]/[% c("var/apt_utils_package_filename") %]'
    sha256sum: '[% c("var/apt_utils_package_sha256sum") %]'
    enable: '[% c("var/apt_utils_package_filename") %]'
  - URL: '[% c("var/apt_packages_baseurl") %]/[% c("var/libapt_inst_package_filename") %]'
    sha256sum: '[% c("var/libapt_inst_package_sha256sum") %]'
    enable: '[% c("var/libapt_inst_package_filename") %]'
  - URL: '[% c("var/apt_packages_baseurl") %]/[% c("var/libapt_pkg_package_filename") %]'
    sha256sum: '[% c("var/libapt_pkg_package_sha256sum") %]'
    enable: '[% c("var/libapt_pkg_package_filename") %]'
